﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PBOffice.BLL;

public partial class MsgMng_Default : System.Web.UI.Page
{
	protected void Page_Init()
	{
		tbEndTime.DataBind();
		tbStartTime.DataBind();
	}

	protected string CutStr(string str, int length)
	{
		if (str.Length <= length)
			return str;
		else
			return str.Substring(0, length - 1) + "…";
	}

	protected void Page_Load(object sender, EventArgs e)
	{
		
	}

	protected void gvMessage_RowCommand(object sender, GridViewCommandEventArgs e)
	{
		switch (e.CommandName)
		{
			case "ChangePublishState":
				int id = Convert.ToInt32(e.CommandArgument);
				using (MsgMngBLL msg = new MsgMngBLL())
				{
					msg.ChangePublishState(id);
					gvMessage.DataBind();
				}
				break;
			case "DeleteMsg":
				int mid = Convert.ToInt32(e.CommandArgument);
				using (MsgMngBLL msg = new MsgMngBLL())
				{
					msg.DeleteMess(mid);
					gvMessage.DataBind();
				}
				break;
			default:
				break;
		}
	}

	protected void rbDay_CheckedChanged(object sender, EventArgs e)
	{
		if (rbDay.Checked)
		{
			tbStartTime.Text = DateTime.Now.ToShortDateString();
			tbEndTime.Text = DateTime.Now.ToShortDateString();
		}
	}
	protected void rbWeek_CheckedChanged(object sender, EventArgs e)
	{
		if (rbWeek.Checked)
		{
			int n = (int)DateTime.Now.DayOfWeek;
			DateTime date = DateTime.Today;
			tbStartTime.Text = date.AddDays(0 - n).ToShortDateString();
			tbEndTime.Text = date.AddDays(6 - n).ToShortDateString();
		}
	}

	protected void rbMonth_CheckedChanged(object sender, EventArgs e)
	{
		if (rbMonth.Checked)
		{
			tbStartTime.Text = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).ToShortDateString();
			tbEndTime.Text = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)).ToShortDateString();
		}
	}
}